home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Format / ascii2fax / bitmap_util.c next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  2.9 KB  |  151 lines

  1. /* bitmap_util.c: utility routines for a bitmap */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Format/ascii2fax/RCS/bitmap_util.c,v 6.0 1991/12/18 20:15:19 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Format/ascii2fax/RCS/bitmap_util.c,v 6.0 1991/12/18 20:15:19 jpo Rel $
  9.  *
  10.  * $Log: bitmap_util.c,v $
  11.  * Revision 6.0  1991/12/18  20:15:19  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15. #include    "fonts.h"
  16.  
  17. BitMap
  18. new_bitmap(wid, ht)
  19. int    wid, ht;
  20. {
  21.     BitMap    ret = (BitMap) calloc(ht, sizeof (BitLine));
  22.     int    i;
  23.     for (i = 0; i < ht; i++)
  24.         ret[i] = (BitLine) calloc(BL_WD2INT(wid), sizeof(int));
  25.     return ret;
  26. }
  27.  
  28. clr_bitmap(map, wid, ht)
  29. BitMap  map;
  30. int     wid, ht;
  31. {
  32.         int     i;
  33.         for (i =0;i < ht;i++)
  34.                 bzero((char *)map[i], BL_WD2INT(wid) * sizeof(int));
  35. }
  36.  
  37. free_bitmap(b, w, h)
  38. BitMap    b;
  39. int    w, h;
  40. {
  41.     int    i;
  42.     for (i = 0; i < h; i++)
  43.         free(b[i]);
  44.     free(b);
  45. }
  46.  
  47. bitmap2file(fp, b, w, h)
  48. FILE    *fp;
  49. BitMap    *b;
  50. int    w, h;
  51. {
  52.     int    iy, ix, count = 0;
  53.     fprintf(fp, "%d %d\n", w, h);
  54.     for (iy = 0; iy < h; iy++) 
  55.         for (ix = 0; ix < BL_WD2INT(w); ix ++) {
  56.             fprintf(fp, "0x%8.8x\n", b[iy][ix]);
  57. #ifdef NOTDEF
  58.             if (++count >= 10) {
  59.                 fprintf(fp, "\n");
  60.                 count = 0;
  61.             }
  62. #endif
  63.         }
  64. #ifdef NOTDEF
  65.     if (w || h)
  66.         fprintf(fp, "\n");
  67. #endif
  68. }    
  69.  
  70. BitMap
  71. file2bitmap(fp, pw, ph)
  72. FILE    *fp;
  73. int    *pw, *ph;
  74. {
  75.     char    buf[BUFSIZ], *argv[15];
  76.     int    argc, ia, iw, ih;
  77.     long    temp;
  78.     BitMap    ret;
  79.  
  80.     if (fgets(buf, BUFSIZ, fp) == NULLCP) {
  81.         fprintf(stderr,
  82.             "Incorrect file encoding of bitmap: unexpected EOF\n");
  83.         return (BitMap) NOTOK;
  84.     }
  85.     
  86.     if ((argc = sstr2arg(buf, 15, argv, " ")) != 2) {
  87.         fprintf(stderr,
  88.             "Incorrect file encoding of bitmap: expecting 'width height'\n");
  89.         return (BitMap) NOTOK;
  90.     }
  91.     
  92.     *pw = (int) strtol(argv[0], NULL, 0);
  93.     *ph = (int) strtol(argv[1], NULL, 0);
  94.     
  95.     ret = new_bitmap(*pw, *ph);
  96.     
  97.     ia = argc = 0;
  98.     for (ih = 0; ih < *ph; ih ++) 
  99.         for (iw = 0; iw < BL_WD2INT(*pw); iw ++) {
  100.             if (ia == argc) {
  101.                 /* read in another line */
  102.                 if (fgets(buf, BUFSIZ, fp) == NULLCP) {
  103.                     fprintf(stderr,
  104.                         "Incorrect file encoding of bitmap: unexpected EOF\n");
  105.                     return (BitMap) NOTOK;
  106.                 }
  107.     
  108.                 argc = sstr2arg(buf, 15, argv, " ");
  109.                 ia = 0;
  110.             }
  111.             temp = strtol(argv[ia++], NULL, 0);
  112.             
  113.             ret[ih][iw] = (int) temp;
  114.         }
  115.     return ret;
  116. }
  117.  
  118.     
  119. int
  120. insertbitmap(to, to_wid, to_ht,
  121.          from, from_wid, from_ht,
  122.          x, y)
  123. BitMap    to;
  124. int    to_wid, to_ht;
  125. BitMap    from;
  126. int    from_wid, from_ht,
  127.     x, y;
  128. {
  129.     int    ix, iy;
  130.     if (from_wid + x > to_wid) {
  131.         fprintf(stderr,
  132.                "insertbitmap: bitmap too wide to insert");
  133.         return NOTOK;
  134.     }
  135.     if (from_ht + y > to_ht) {
  136.         fprintf(stderr,
  137.                "insertbitmap: bitmap too tall to insert");
  138.         return NOTOK;
  139.     }
  140.  
  141.     for (iy = 0; iy < from_ht && y+iy < to_ht; iy++) {
  142.         for (ix = 0; ix < from_wid && x+ix < to_wid; ix++) {
  143.             if (BL_ISSET(ix, from[iy]))
  144.                 BL_SET(x+ix, to[y+iy]);
  145.             else
  146.                 BL_CLR(x+ix, to[y+iy]);
  147.         }
  148.     }
  149.     return OK;
  150. }
  151.